<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var a = [1, 2];
        var b = [4, 5, 6, 7];

        function expandArr(arr1, arr2) {
            const length = arr1.length > 0 ? arr1.length : 1;
            const twoLen = arr2.length > 0 ? arr2.length : 1;
            let result = [];
            for (let i = 0; i < length; i++) {
                for (let j = 0; j < twoLen; j++) {
                    result.push({
                        a: arr1[i] || '',
                        b: arr2[j] || ''
                    });
                }
            }
            return result;
        }
        console.log(expandArr(a, b))
    </script>
</body>
</html>